var app = getApp(),

  $ = require("../../utils/httpHelper.js")
var wxParse = require("../../wxParse/wxParse.js")
Page({
  data: {
    activity_info: {},
    activityid:'',
    userInfo: {},
    size:['1','2','3','4','5'],
    isbtn:true,
    showdialog: false,
    pay_type:''
  },
  onShareAppMessage: function (res) {
    app.shareApp(res)
  },
  onLoad: function (options) {
    if (!app.check_empty(options.id)) {
      $.httpPost("activity_detail", { activity_id: options.id}, (data, err) => {
        this.setData({
          activity_info:data.data,
          activityid: options.id
        })
        wxParse.wxParse("about", "html", data.data.content, this)
      })
    }
    if (!app.check_empty(options.from) && options.from == "my"){
      this.setData({
        isbtn:false
      })
    }
    
    
  },
  formSubmit: function (e) {
    if (app.checkPhone(e.detail.value.userphone)) {
      var rd_session = wx.getStorageSync('rd_session');
      var param = { rd_session: rd_session, name: e.detail.value.username, phone: e.detail.value.userphone }
      $.httpPost("edit_member_info", param, (data, err) => {
        wx.showToast({
          title: data.message,
          duration: 2000
        })
        this.setData({
          showdialog: false
        })
        this.join()
      })
    }else{
      wx.showToast({
        title: '手机号格式错误',
        duration: 2000,
      })
    }
    
    console.log('form发生了submit事件，携带数据为：', e.detail.value)
  },
  formReset: function () {
    this.setData({
      showdialog: false
    })
    console.log('form发生了reset事件')
  },
  join(){
    app.checkUser((data) => {
      console.log(data)
      if (data) {
        //支付
        var rd_session = wx.getStorageSync('rd_session');
          $.httpPost("join_activity", { activity_id: this.data.activityid, rd_session: rd_session, pay_type: this.data.pay_type }, (data, err) => {
            if (data.result == "success") {
              app.wxpay_activity(data.data.order_no, app.globalData.userInfo.openId);
            } else {
              wx.showToast({
                title: data.message
              })
            }
          })
      } else {
        this.setData({
          showdialog: true
        })
      }
    })
  }
  
  
});